import Poster from '../../../components/wxa-plugin-canvas/poster/poster';
import posterConfig from '../../utils/posterConfig';

Page({
  data: {
    // posterConfig: posterConfig.fftGoodsConfig,
    // posterConfig: posterConfig.fftBuyConfig,
    posterConfig: posterConfig.fftPosterConfig,
    posterImage: '',
    isOverShare: true
  },
  onPosterSuccess(e) {
    const { detail } = e;
    this.setData({ posterImage: detail });
  },
  onPosterFail(err) {
    console.error(err);
  },

  previewImage(e) {
    const { src } = e.currentTarget.dataset;
    wx.previewImage({
      current: src,
      urls: [src]
    })
  },

  /**
   * 异步生成海报
   */
  onCreatePoster() {
    this.setData({ posterConfig: posterConfig.fftPosterConfig }, () => {
      Poster.create(true);    // 入参：true为抹掉重新生成
    });
  },
  onCreateAfterBuy() {
    this.setData({ posterConfig: posterConfig.fftBuyConfig }, () => {
      Poster.create(true);    // 入参：true为抹掉重新生成 
    });
  },
  onCreateGoodsDetail() {
    this.setData({ posterConfig: posterConfig.fftGoodsConfig }, () => {
      Poster.create(true);    // 入参：true为抹掉重新生成 
    });
  },

  onLoad() {
    const that = this;
    // let { posterConfig } = that.data;
    // posterConfig.backgroundColor = '#fff';
    // posterConfig.texts[0].text[0].text = '立即跟团';
    // posterConfig.images[0].url = 'https://6c6f-love-0g1b6yqybf5521f5-1316718936.tcb.qcloud.la/story/story1710724494966.png';
    // that.setData({
    //   posterConfig
    // }, () => {
    //   Poster.create(true);    // 入参：true为抹掉重新生成
    // })
  },

  //分享给好友
  onShareAppMessage() {
    return {
      title: "商品详情标题",
      path: '/packageElement/pages/imgCombine/imgCombine', //分享页面地址
      imageUrl: this.data.posterImage,
    };
  },
  // 分享到朋友圈
  onShareTimeline() { },
})